package com.top10.controller;

import com.top10.bean.ResponseBean;
import com.top10.service.ICouponGoodsService;
import com.top10.service.IGoodsDetailedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author sny
 * @Package com.top10.controller.mobile
 * @date 2018/9/30
 */
@RestController
@RequestMapping("/top10/goodsdetail")
public class GoodsDetailController {


    @Autowired
    private ICouponGoodsService iCouponGoodsService;
    @Autowired
    private IGoodsDetailedService iGoodsDetailedService;



   /* *//**
     * 商品详情
     * @param goodsuuid
     * @return
     *//*

    @PostMapping("/goodsdetailinfo")
    public ResponseBean goodsDetail(String goodsuuid,long specialtype){
        if (goodsuuid == null || goodsuuid.equals(" ")) {

            return ResponseBean.createError("goodsId不能为空");
        }
        //  GoodsDetailedVo goodsDetailed=iGoodsDetailedService.selectGoodsDetailById(goodsId);
        List<Map<String, Object>> goodsDetailed = iGoodsDetailedService.selectGoodsDetailById(goodsuuid, specialtype);
        List list = new ArrayList();
        List<Map<String, Object>> goodscoupon = iCouponGoodsService.selectgoodscoupon(goodsuuid);
        if (goodscoupon.size() != 0) {
            for (Map<String, Object> map : goodscoupon) {
                Object amount = map.get("amount");
                list.add(amount);
            }
            Object amount1 = Collections.min(list);


            return ResponseBean.createSuccess().addData("goodsDetailed", goodsDetailed).addData("amount", amount1);
        }
        return ResponseBean.createSuccess().addData("goodsDetailed", goodsDetailed);

    }*/

    /**
     * 商品详情
     * @param goodsuuid
     * @return
     *
     * 修改这个接口的时候要注意,自己增添了一些东西
     *
     */

    @PostMapping("/specialGoodsDetail")
    public ResponseBean specialGoodsDetail(String goodsuuid){
        if(goodsuuid == null ||goodsuuid.equals(" ")){

            return ResponseBean.createError("goodsId不能为空");
        }
        //  GoodsDetailedVo goodsDetailed=iGoodsDetailedService.selectGoodsDetailById(goodsId);
        int amount2=0;
        List<Map<String, Object>> goodsDetaileds=iGoodsDetailedService.selectSpecialGoodsDetailById(goodsuuid);
        List list = new ArrayList();
        List<Map<String, Object>> goodscoupon = iCouponGoodsService.selectgoodscoupon(goodsuuid);
        if (goodscoupon.size() != 0) {
            for (Map<String, Object> map : goodscoupon) {
                Object amount = map.get("amount");
                list.add(amount);
            }
            Object amount1 = Collections.min(list);
            return ResponseBean.createSuccess().addData("goodsDetaileds",goodsDetaileds).addData("amount",amount1);
        }

            return ResponseBean.createSuccess().addData("goodsDetaileds",goodsDetaileds).addData("amount",amount2);
    }

    @PostMapping("/goodsDetail")
    public ResponseBean goodsDetail(String goodsuuid){
        if(goodsuuid == null ||goodsuuid.equals(" ")){

            return ResponseBean.createError("goodsId不能为空");
        }
        //  GoodsDetailedVo goodsDetailed=iGoodsDetailedService.selectGoodsDetailById(goodsId);
        int amount2=0;
        List<Map<String, Object>> goodsDetaileds=iGoodsDetailedService.selectGoodsDetailById(goodsuuid);
        List list = new ArrayList();
        List<Map<String, Object>> goodscoupon = iCouponGoodsService.selectgoodscoupon(goodsuuid);
        if (goodscoupon.size() != 0) {
            for (Map<String, Object> map : goodscoupon) {
                Object amount = map.get("amount");
                list.add(amount);
            }
            Object amount1 = Collections.min(list);
            return ResponseBean.createSuccess().addData("goodsDetaileds",goodsDetaileds).addData("amount",amount1);
        }

        return ResponseBean.createSuccess().addData("goodsDetaileds",goodsDetaileds).addData("amount",amount2);
    }
/*

    @PostMapping("/")
    public ResponseBean
*/



}
